<?php
/**
 * 列表最小主键
 * User: dxk
 * Date: 2020/07/18
 */
namespace App\Component\ListService;

use Illuminate\Database\Query\Builder;

trait ListMinPrimaryTrait
{
    protected $min_primary_id = null;

    /**
     * 设置最小主键ID
     * @param int $min_primary_id
     * @return $this
     */
    public function setMinPrimaryId(int $min_primary_id)
    {
        $this->min_primary_id = $min_primary_id;
        return $this;
    }

    /**
     * 导出数据、后台执行脚本时使用
     * @param Builder $query_obj
     * @return Builder
     */
    protected function minPrimaryQuery(Builder $query_obj)
    {
        if (is_numeric($this->min_primary_id)) {
            $query_obj->where($this->primary_key, '>', $this->min_primary_id);
            $query_obj->orderBy($this->primary_key, 'ASC');
        }
        return $query_obj;
    }
}
